<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // n*n
  function insertSort (arr) {
      let tem
      for (let i = 0; i < arr.length; i++) {
        tem = arr[i]
        for (let j = i; j >= 0; j--) {
          if (arr[j - 1] > tem) {
            arr[j] = arr[j - 1]
          } else {
            arr[j] = tem
            break
          }
        }
      }
      return arr
    }
    console.log(insertSort([3, 44, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48]))
  </script>
</body>
</html>